<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 编写 getAverageAge(users) 函数，该函数获取一个具有 age 属性的对象数组，并返回平均年龄。
        let arr = [
            { name: "John", age: 25 },
            { name: "Pete", age: 30 },
            { name: "Mary", age: 28 }
        ];
        function getAverageAge(arr) {
            let a = 0;
            let avg = 0;
            arr.map(function (callback) {
                avg += callback.age;
                a++;
            })
            avg = avg / a;
            return avg;
        }
        console.log(getAverageAge(arr));    // 25+30+28/3
    </script>
</body>

</html>